package com.mini.util;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.util.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author gaoyanfeng
 * @create 2019-08-02 11:30
 **/
public class MatcherRule {
    public static boolean isMobileNO(String mobiles) {
        if(TextUtils.isEmpty(mobiles)){
            return false;
        }

        //1[3|4|5|7|8][0-9]表示以1开头，后跟3,4,5,7,8，[0-9]表示数字即可，\d{8}剩余八位填充随意数字
//        Pattern p = Pattern.compile("^((13[0-9])|(14[5-9])|(15[0-3,5-9])|(17[0-8])|(18[0-9])|(19[1,8,9])|(16[6,5]))\\d{8}$");
        Pattern p = Pattern.compile("^1[0-9]{10}$");
        Matcher m = p.matcher(mobiles);
        return m.matches();
    }

    /**
     * 判断是否存在汉字
     * @param countname
     * @return
     */
    public static boolean checkcountname(String countname)
    {
        Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
        Matcher m = p.matcher(countname);
        if (m.find()) {
            return true;
        }
        return false;
    }

    /**
     * 是否是数字
     * @param str
     * @return
     */
    public static boolean isInteger(String str) {
        if(StringUtils.isBlank(str)){
            return false;
        }
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        return pattern.matcher(str).matches();
    }

    /**
     * 校验是否为数字
     *
     * @param str
     * @return
     */
    public static boolean isNumeric(String str){
        for (int i = str.length();--i>=0;){
            if (!Character.isDigit(str.charAt(i))){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        String mobile = "18511812005";
        System.out.println(MatcherRule.isMobileNO(mobile));
    }
}
